<?php
/**
 * @ClassName: Boxpay
 * @Description: TODO
 * @author: gydtrade
 * @Date: 2025-10-09 00:37
 * @Version: V1.0.0
 */

namespace app\api\controller;

use app\common\model;
use think\Controller;

class Boxpay extends Controller
{
    /**
     * 获取行业类目
     * @return \think\response\Json
     */
    function getBusinessMcc()
    {
        $data = model\boxpay\BusinessMcc::where(['pcode' => 0])->where('is_show', 1)->select();
        return json(['code' => 1, 'msg' => 'ok', 'data' => $data]);
    }

    /**
     * 获取开户行信息
     * @return \think\response\Json
     */
    function checkBankName()
    {
        $bankName = input("bankName");
        if (!$bankName) {
            return json(["code" => 0, "msg" => "请输入银行名称"]);
        }
        $where = [];
        $where[] = ["parent_name", "like", "%" . $bankName . "%"];
        $find = model\boxpay\BankNo::where($where)->find();
        if (!$find) {
            return json(["code" => 0, "msg" => "查不到该银行"]);
        } else {
            $find['full_name'] = $find['parent_name'];
            $find['bank_no'] = $find['parent_no'];
        }
        return json(["code" => 1, "msg" => "银行查找成功", "data" => $find]);
    }

    /**
     * 获取区域支行
     * @return \think\response\Json
     */
    function getSubBranch()
    {
        $city_code = input("city_code", '');
        $bank_full_name = input("bank_full_name", '');
        $branch_name = input('branch_name', '');
        if (!$city_code) {
            return json(["code" => 0, "msg" => "请选择区域"]);
        }

        $where = [
            ['city_code', '=', $city_code],
            ['parent_name', '=', $bank_full_name],
        ];

        if ($branch_name) {
            $where[] = ['sub_name', 'like', '%' . $branch_name . '%'];
        }
        $list = model\boxpay\BankNo::where($where)
            ->field('sub_no as code,sub_name as name')
            ->select();
        return json(["code" => 1, "msg" => "区域支行查找成功", "data" => $list]);
    }

}